<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title></title>
    <meta name="keywords" content="">
    <meta name="description" content="">
    <link rel="shortcut icon" href="favicon.ico"> 
	<link href="__PUBLIC__/admin/css/bootstrap.min.css?v=3.3.6" rel="stylesheet">
    <link href="__PUBLIC__/admin/css/font-awesome.css?v=4.4.0" rel="stylesheet">
    <link href="__PUBLIC__/admin/css/style.css?v=4.1.0" rel="stylesheet">
    <script src="__PUBLIC__/admin/js/jquery.min.js?v=2.1.4"></script>
</head>

<script>
var url = "{:url('config/lst')}";
var checkCname = "{:url('config/checkCname')}";
var checkEname = "{:url('config/checkEname')}";
var insertUrl = "{:url('config/add')}";
</script>
<body class="gray-bg">
<style>
input.error{
	border:1px solid red;
}
span.error{
	padding-top:10px;
	color: #f00;
	font-size:12px;
}
</style>
    <div class="wrapper wrapper-content">
        <div class="row">
            <div class="col-sm-12">
                <div class="ibox float-e-margins">
                    <div class="ibox-title">
                        <h5>增加系统配置</h5>
                    </div>
                    <div class="ibox-content">
                        <form method="post" class="form-horizontal" id="form">
                            <div class="form-group">
                                <label class="col-sm-2 control-label">所属分类：</label>
                                <div class="col-sm-6">
                                    <select class="form-control m-b" name="ca_id">
                                        {foreach name="cationres" item="v"}
                                        <option value="{$v.id}">{$v.ca_name}</option>
                                        {/foreach}
                                    </select>
                                </div>
                            </div>
                            <div class="hr-line-dashed"></div>
                            <div class="form-group">
                                <label class="col-sm-2 control-label">配置名称：</label>
                                <div class="col-sm-6">
                                    <input type="text" name="cname" class="form-control">
                                </div>
                                <label class="col-sm-1" style="padding-top:7px; color:#F00; font-size:16px;">*</label>
                            </div>
                            <div class="hr-line-dashed"></div>

                            <div class="form-group">
                                <label class="col-sm-2 control-label">英文名称：</label>
                                <div class="col-sm-6">
                                    <input type="text" name="ename" class="form-control">
                                </div>
                                <label class="col-sm-1" style="padding-top:7px; color:#F00; font-size:16px;">*</label>
                            </div>
                            <div class="hr-line-dashed"></div> 
                            


                            <div class="form-group">
                                <label class="col-sm-2 control-label">类型：</label>
                                <div class="col-sm-6">
                                    <select class="form-control m-b" name="type">
                                         <option value="0">文本框</option>
                                         <option value="1">文本域</option>
                                         <option value="2">单选按钮</option>
                                         <option value="3">复选框</option> 
                                         <option value="4">下拉框</option>
										 <option value="5">图片</option>   
                                    </select>
                                </div>
                            </div>
                            <div class="hr-line-dashed"></div> 

                            <div class="form-group">
                                <label class="col-sm-2 control-label">配置可选值：</label>
                                <div class="col-sm-6">
                                    <textarea name="values" id="values" class="form-control" disabled="diasabled"></textarea>
                                </div>  
                                <label class="col-sm-2" style="padding-top:7px; color:#333; font-size:12px;">(多个以英文,号隔开)</label>
                            </div>
                            <div class="hr-line-dashed"></div>

                            <div class="form-group">
                                <label class="col-sm-2 control-label">备注：</label>
                                <div class="col-sm-6">
                                    <textarea name="remarks" class="form-control"></textarea>
                                </div>
                                <label class="col-sm-2" style="padding-top:7px; color:#333; font-size:12px;">(配置提示信息)</label>
                            </div>
                            <div class="hr-line-dashed"></div>

                               
                            <div class="form-group">
                                <div class="col-sm-4 col-sm-offset-2">
                                    <button class="btn btn-primary" type="submit" id="doSubmit" style="margin-right:100px;">保存内容</button>
                                    <button type="reset" class="btn btn-default">重置</button>
                                </div>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </div>


    <!-- 全局js -->
    <script src="__PUBLIC__/admin/js/bootstrap.min.js?v=3.3.6"></script>
    <!-- 自定义js -->
    <script src="__PUBLIC__/admin/js/plugins/layer/layer.min.js"></script>
    <script src="__PUBLIC__/admin/js/plugins/validate/jquery.validate.min.js"></script>	
    <!-- iCheck -->
    <script src="__PUBLIC__/admin/js/plugins/iCheck/icheck.min.js"></script>
    <script src="__PUBLIC__/admin/js/common/ajax.js"></script>      
	<script>
    	$(function(){ 	    
            $('select[name=type]').change(function(){
            	var type = $(this).val();
            	if(type != 0 && type != 1 && type != 5){
            		$('#values').removeAttr('disabled');
            	}else{
            		$('#values').prop('disabled','disabled');
            	}
            });

    	    var icon = "<i class='fa fa-times-circle'></i>&nbsp;&nbsp;";
        	$('#form').validate({
	        	errorElement : 'span',
	        	debug: true,//只验证不提交表单
	        	//layer ajax提交表单
	            submitHandler:function(){
	            	var configType = $('select[name=type]').val();
	            	var values = $('#values').val();
	            	if(configType != 0 && configType != 1 && configType != 5){
	            		if(values == ''){
		                	layer.msg('属性可选值不能为空', {icon: 2,time: 2000});
		                	return false;
	            		}
	                }
					
	               // 序列化 表单数据 后提交 ，太简洁了
	            	post(insertUrl,'POST',$('#form').serialize(),1);
	                return false;
	            },//这是关键的语句，配置这个参数后表单不会自动提交，验证通过之后会去调用的方法

	        	rules:{
	        		cname:{
	        			required:true,
		        		remote : {
			        	    url : checkCname,
			        	    type : 'post',
			        		dataType : 'json',
			        		data : {
			        			cname : function () {
			        			    return $('input[name=cname]').val();
			        	        }
			        		}
			        	}	        			
	        	    },

	        		ename:{
	        			required:true,
		        		remote : {
			        	    url : checkEname,
			        	    type : 'post',
			        		dataType : 'json',
			        		data : {
			        			ename : function () {
			        			    return $('input[name=ename]').val();
			        	        }
			        		}
			        	}	        			
	        	    },
	        	    
	        		ca_id:{
	        			required:true,
	        			digits:true
	        	    },
	        	    
	        	    type:{
	        	    	required:true,
	        	    	digits:true
	        	    }

	        	},

	        	messages:{
	        		cname:{
	        			required:icon+'必填',
	        			remote:icon+'配置中文名已存在'
	        	    },
	        		ename:{
	        			required:icon+'必填',
	        			remote:icon+'配置英文名已存在'
	        	    },
	                ca_id:{
	                	required:icon+'必选',
	                	digits:icon+'选择配置分类参数错误'
	                },
	                type:{
	                	required:icon+'必选',
	                	digits:icon+'选择配置类型参数错误'
	                }
	        	}
        	});
      });

	  function cl(){
	     location.href = url;
	  }	  
    </script>
</body>
</html>
